
library(stringr)
library(dplyr)

two_rolls <- function(){
  sample(1:6, size=2, replace = TRUE)
}

print(two_rolls())

many_rolls <- replicate(50000, two_rolls())

equal_cn <- sum(many_rolls[1,] == many_rolls[2,])

print(equal_cn)

print(equal_cn / dim(many_rolls)[2])
print(1/6)


box <- c("red", "red", "red", "blue", "white")

rolls <- function(){
  sample(box, size=3, replace = FALSE)
}

retM <- replicate(10000, rolls())

print(retM)

# all_red_cn <- sum(retM[1])

print(dim(retM))

red_rows <- sum(apply(retM, 2, function(clm) all(clm == "red")))

print(red_rows/ dim(retM)[2])

permU <- function(input,st) {
  str_flatten(sample(input, size=st), collapse= ",")
}

songs <- c("Song A", "Song B", "Song C", "Song D", "Song E", "Song F")

sample(songs, size=3)

str_flatten(sample(songs, size=3), collapse=' ')

permU(songs, 3)

nm <- c(1,2,3,4,5)

gm <- combn(nm, 2)

gm_t <- t(gm)

N <- nrow(gm_t)

df <- data.frame(Iter = 1:500, Balls = gm_t[sample(N, size=500, replace = TRUE),])

df %>% group_by(Balls.1, Balls.2) %>% count()
